<?php

/**
 * Description of access
 * 
 * @author 叶风
 * Qq:    355007778
 * Email: ye.fn@163.com
 */

namespace c\log\access;

class a extends \control
{
    var $table = 'log_access';
    var $tables = array('t1'=>array('as'=>'log_access'),
                        'at'=>array('join'=>'JOIN', 'on'=>'at.id=t1.id', 'as'=>'log_access_time'));
    var $class = array('PU'=>'\c\auth\permission');

    function index_home()
    {
        $this->PU->login();
        $this->title = \lang::g('Log Access');
        $res = $this->db->group('t1.id')->get_page(array(), $this->tables, 't1.*, DATE_FORMAT(time, "%m-%d") time', 'at.user_id='. \YF_f::$login_user_id, 'at.time DESC');
        $this->loadTemplate('user/access_goods', array('res'=>$res));
        $this->display('user');
    }
    function index_del()
    {
        $this->PU->login();
        $id = intval($_GET['id']);
        $b = $this->db->save('log_access_time', array('user_id'=>0), "id IN($id) AND user_id=". \YF_f::$login_user_id);
		ajax_json(TRUE);
    }
    
    // 清除3个月前
    function index_cl()
    {
        $this->PU->check('log\aeecss');
        $w = 'time<"' . date('Y-m-d', strtotime('-3 month')) .'"';
        
        $this->tables['at']['join'] = 'RIGHT JOIN';
        $this->db->del($this->tables, $w);
        ajax_json(TRUE);
    }
    function index_statistic()
    {
        $this->PU->check('log\aeecss');
        \control::$template_dir = TEMPLATE_DIR_A;
        
        $this->title = \lang::g('Log Access');
        $s = $this->P_G('s');
        $w = '';
        $s['timeS'] && $w = 'time>="'. $this->db->escape($s['timeS']) . '"';
        
        $t = $this->tables;
        $t['at']['join'] = 'LEFT JOIN';
        $t['user'] = array('join'=>'LEFT JOIN', 'on'=>'user.id=at.user_id');
        $res = $this->db->group('t1.id')->get_page(array(), $t, 't1.url, t1.title, count(at.id) num, at.time, user.name userName', $w, 'num DESC, time DESC');
        $this->loadTemplate('log/access', array('res'=>$res));
    }
}
